package utils

import (
	"encoding/base64"
	"fmt"
	"strconv"
	"time"
)

func ReverseSlice(sli []string) {
	for i := 0; i < int(len(sli)/2); i++ {
		li := len(sli) - i - 1
		sli[i], sli[li] = sli[li], sli[i]
	}
}

func FormatDate(t int64) string {
	timeLayout := "2006-01-02 15:04:05"
	return time.Unix(t, 0).Format(timeLayout)
}

func CutDecimal(value float64) float64 {
	value, _ = strconv.ParseFloat(fmt.Sprintf("%.2f", value), 64)
	return value
}

func DecodeNickName(encodeString string) string {
	decodeBytes, err := base64.StdEncoding.DecodeString(encodeString)
	if err != nil {
		return encodeString
	} else {
		return string(decodeBytes)
	}
}

//删除slice中指定的元素
func RemoveSliceElement(sliceList []int64, val int64) []int64 {
	if len(sliceList) > 0 {
		for i := 0; i < len(sliceList); i++ {
			if sliceList[i] == val {
				sliceList = append(sliceList[:i], sliceList[i+1:]...)
			}
		}
	}
	return sliceList
}